{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "TRAIN_MALWARE = '../data/train/malware'\n",
    "TRAIN_NORMAL = '../data/train/normal'\n",
    "VALID_MALWARE = '../data/valid/malware'\n",
    "VALID_NORMAL = '../data/valid/normal'\n",
    "\n",
    "train_malwares = os.listdir(TRAIN_MALWARE)\n",
    "train_normals = os.listdir(TRAIN_NORMAL)\n",
    "valid_malwares = os.listdir(VALID_MALWARE)\n",
    "valid_normals = os.listdir(VALID_NORMAL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集中的恶意软件数量为： 7857\n",
      "训练集中的正常软件数量为： 7857\n",
      "验证集中的恶意软件数量为： 1963\n",
      "验证集中的正常软件数量为： 1965\n"
     ]
    }
   ],
   "source": [
    "print(\"训练集中的恶意软件数量为：\", len(train_malwares))\n",
    "print(\"训练集中的正常软件数量为：\", len(train_normals))\n",
    "print(\"验证集中的恶意软件数量为：\", len(valid_malwares))\n",
    "print(\"验证集中的正常软件数量为：\", len(valid_normals))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_malwares = [x.split('.')[0] for x in train_malwares]\n",
    "train_normals = [x.split('_')[0] for x in train_normals]\n",
    "valid_malwares = [x.split('.')[0] for x in valid_malwares]\n",
    "valid_normals = [x.split('_')[0] for x in valid_normals]\n",
    "\n",
    "def count(xlist):\n",
    "    counts = {}\n",
    "    for x in xlist:\n",
    "        if x not in counts:\n",
    "            counts[x] = 1\n",
    "        else:\n",
    "            counts[x] += 1\n",
    "    return counts\n",
    "\n",
    "train_malwares_count = count(train_malwares)\n",
    "valid_malwares_count = count(valid_malwares)\n",
    "train_normals_count = count(train_normals)\n",
    "valid_normals_count = count(valid_normals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def print_count(count_dict):\n",
    "    for i, x in enumerate(count_dict):\n",
    "        print('{}.'.format(i+1), x, count_dict[x])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. IM-Worm 19\n",
      "2. Exploit 85\n",
      "3. Trojan-PSW 764\n",
      "4. Trojan-Spy 584\n",
      "5. Trojan-Downloader 1968\n",
      "6. Trojan-Dropper 398\n",
      "7. Net-Worm 86\n",
      "8. Trojan-Banker 210\n",
      "9. Trojan-GameThief 1264\n",
      "10. Backdoor 2287\n",
      "11. Email-Worm 138\n",
      "12. IRC-Worm 21\n",
      "13. P2P-Worm 33\n"
     ]
    }
   ],
   "source": [
    "print_count(train_malwares_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. IM-Worm 1\n",
      "2. Exploit 23\n",
      "3. Trojan-PSW 209\n",
      "4. Trojan-Spy 121\n",
      "5. Trojan-Downloader 497\n",
      "6. Trojan-Dropper 80\n",
      "7. Net-Worm 15\n",
      "8. Trojan-Banker 52\n",
      "9. Trojan-GameThief 330\n",
      "10. Backdoor 591\n",
      "11. Email-Worm 32\n",
      "12. P2P-Worm 8\n",
      "13. IRC-Worm 4\n"
     ]
    }
   ],
   "source": [
    "print_count(valid_malwares_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. win10 2801\n",
      "2. win7 3908\n",
      "3. win8 862\n",
      "4. winxp 286\n"
     ]
    }
   ],
   "source": [
    "print_count(train_normals_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. win10 706\n",
      "2. win7 989\n",
      "3. win8 202\n",
      "4. winxp 68\n"
     ]
    }
   ],
   "source": [
    "print_count(valid_normals_count)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
